<?php
namespace Middleware;

use Model\Model;

class Auth
{
    //登录授权,如果有sessionid取出来 验证token,然后把用户信息放入request中
    function request($request){
        $model = new Model();
        $session = $token = $request['cookie']['session'];
        $st = $model->prepare("select u.id as id,u.username as username from `tbSessions` as s join `tbUsers` as u on s.uid=u.id where s.`session`=? and s.`session_expire_time`>=?");
        $date = date('Y-m-d H:i:s');
        $st->bindParam(1, $session);
        $st->bindParam(2, $date);
        $st->execute();
        $info = $st->fetchAll();
        if($info != []){
            $info = $info[0];
            $request['username'] =$info['username'];
            $request['uid'] = $info['id'];
        }
        return $request;
    }
    function response($html){
        return $html;
    }
}